package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QImTj;
import com.ruoyi.system.service.IQImTjService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * IM会话统计Controller
 * 
 * @author ruoyi
 * @date 2024-06-25
 */
@Controller
@RequestMapping("/system/tj")
public class QImTjController extends BaseController
{
    private String prefix = "system/tj";

    @Autowired
    private IQImTjService qImTjService;

    @RequiresPermissions("system:tj:view")
    @GetMapping()
    public String tj()
    {
        return prefix + "/tj";
    }

    /**
     * 查询IM会话统计列表
     */
    @RequiresPermissions("system:tj:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QImTj qImTj)
    {
        startPage();
        List<QImTj> list = qImTjService.selectQImTjList(qImTj);
        return getDataTable(list);
    }

    /**
     * 导出IM会话统计列表
     */
    @RequiresPermissions("system:tj:export")
    @Log(title = "IM会话统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QImTj qImTj)
    {
        List<QImTj> list = qImTjService.selectQImTjList(qImTj);
        ExcelUtil<QImTj> util = new ExcelUtil<QImTj>(QImTj.class);
        return util.exportExcel(list, "IM会话统计数据");
    }

    /**
     * 新增IM会话统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存IM会话统计
     */
    @RequiresPermissions("system:tj:add")
    @Log(title = "IM会话统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QImTj qImTj)
    {
        return toAjax(qImTjService.insertQImTj(qImTj));
    }

    /**
     * 修改IM会话统计
     */
    @RequiresPermissions("system:tj:edit")
    @GetMapping("/edit/{imTjId}")
    public String edit(@PathVariable("imTjId") Long imTjId, ModelMap mmap)
    {
        QImTj qImTj = qImTjService.selectQImTjByImTjId(imTjId);
        mmap.put("qImTj", qImTj);
        return prefix + "/edit";
    }

    /**
     * 修改保存IM会话统计
     */
    @RequiresPermissions("system:tj:edit")
    @Log(title = "IM会话统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QImTj qImTj)
    {
        return toAjax(qImTjService.updateQImTj(qImTj));
    }

    /**
     * 删除IM会话统计
     */
    @RequiresPermissions("system:tj:remove")
    @Log(title = "IM会话统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(qImTjService.deleteQImTjByImTjIds(ids));
    }
}
